<template>
    <div>
      <jxf-titletip :title="title" :hasRefresh="false" :hasGoBack="true" @goBack="$emit('goBack')"></jxf-titletip>
      <el-card class="jxf-table-card mt20">
        <div slot="header" class="clearfix">
          <span>基本信息</span>
        </div>
        <div class="listArea">
          <jxf-datalist :info="dataInfo.list">
          </jxf-datalist>
        </div>
      </el-card>
      <div class="mt20">
        <i>备注：</i>
        <div>一旦绑定，供应商所选的行业分类（也就是一级商品分类）只可在该供应商中查看，采购商在其他商户中无法看到相同的行业分类也就是一级商品分类</div>
      </div>
      <div class="mt20" v-if="dataInfo.status == '0'">
        <el-button type="primary" @click="deleteItem">删除</el-button>
      </div>
      <div class="mt20" v-if="dataInfo.status == '1'">
        <el-button type="primary" @click="changeStatus">解绑</el-button>
      </div>
    </div>
</template>

<script>
    export default {
        name: "ProtectDetail",
        props: {
          dataInfo: {
            type: Object,
            default: () => {}
          }
        },
        data() {
          return {
            title: "专属保护详情"
          }
        },
        methods: {
          deleteItem() {
            let data = {
              id: this.dataInfo.id
            }
            this.$confirm('此操作将删除此专属保护记录, 是否继续?', '删除保护关系', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              ajax.post(apis.setting.deleteProtect, data).then(result => {
                if(result.code == '10000000') {
                  this.$message({
                    type: 'success',
                    message: '删除成功!'
                  });
                  this.$emit('fresh')
                  this.$emit('goBack')
                } else {
                  this.$message.error(result.message)
                }
              })

            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消'
              });
            });
          },
          changeStatus() {
            let data = {
              id: this.dataInfo.id
            }
            this.$confirm('此操作将解除绑定, 是否继续?', '解除绑定', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              ajax.post(apis.setting.changeProtectStatus, data).then(result => {
                if (result.code == "10000000") {
                  this.$message({
                    type: 'success',
                    message: '解除绑定成功!'
                  });
                  this.$emit('fresh')
                  this.$emit('goBack')
                } else {
                  this.$message.error(result.message)
                }
              })
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '取消操作'
              });
            });
          },
        }
    }
</script>

<style scoped>

</style>
